package com.qf.rbac2202.config;

import com.qf.rbac2202.shiro.ShiroTag;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.util.HashMap;
import java.util.Properties;

@Configuration
public class FreemarkerConfig {

    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer(ShiroTag shiroTag){

        FreeMarkerConfigurer freeMarkerConfig = new FreeMarkerConfigurer();

        //1.配置freemarker 的模板路径
        freeMarkerConfig.setTemplateLoaderPath("classpath:/templates");
        //2.配置freemarker 解析器 shiroTag
        //即<#if shiro.hasPermission("sys:user:save")>
        HashMap<String, Object> map = new HashMap<>();

        map.put("shiro",shiroTag);
        freeMarkerConfig.setFreemarkerVariables(map);

        //3.配置freemarker  使用的字符编码
        Properties properties = new Properties();
        properties.setProperty("default_encoding", "utf-8");
        properties.setProperty("number_format", "0.##");
        freeMarkerConfig.setFreemarkerSettings(properties);


        return freeMarkerConfig;
    }

}
